package com.william.jdbcplus.core.conditions.segment.impl;

import com.william.jdbcplus.core.enums.SqlKeyword;
import com.william.jdbcplus.core.toolkit.StringPool;

/**
 * update SQL 片段
 * 更新表名
 */
public class UpdateSegmentList extends AbstractSegmentList {

    @Override
    public boolean add(String segment) {
        this.clear();
        return super.add(segment);
    }

    @Override
    public String getSegment() {
        if (isEmpty()) {
            return StringPool.EMPTY;
        }

        String tableName = StringPool.EMPTY;

        for (String item : this) {
            tableName = item;
        }

        return tableName;
    }

    @Override
    public String getSql() {
        if (isEmpty()) {
            return StringPool.EMPTY;
        }
        return SqlKeyword.UPDATE.getSegment() + StringPool.SPACE + getSegment();
    }
}
